package chapter1.fundamentals.exercise;

import common.util.ArrayUtil;
import edu.princeton.cs.algs4.StdRandom;
import org.jetbrains.annotations.Contract;

import java.util.Arrays;

/**
 * @author quanlinlin on 2018/10/26 9:24.
 * @version 1.0
 */
public class E_15 {

    public static void main(String[] args) {
        int[] a = ArrayUtil.getRandomArray();
        System.out.println(Arrays.toString(a));
        int M = StdRandom.uniform(100);
        System.out.println("M is:" + M);

        //Arrays.

        int[] histogram = histogram(a, M);
        //System.out.println(ArrayUtil.arrayToString(histogram));
    }

    @Contract(pure = true)
    private static int[] histogram(int[] a, int m) {
        int[] result = new int[m];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < a.length; j++) {
                if (a[j] == i) {
                    result[i]++;
                }
            }
        }
        return result;
    }


}
